<%--
  Created by IntelliJ IDEA.
  User: lenovo
  Date: 2021/7/1
  Time: 9:07
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>$</title>
</head>
    <title>Title</title>
    <link rel="stylesheet" href="css/css.css">
    <link rel="stylesheet" href="css/img.css">
    <script src="js/jquery-1.8.2.min.js"></script>
    <script src="js/fileupload.js"></script>
    <script>
        $(function () {
            $.ajax({
                url:"city.do",
                data:{"pid":0},
                type:"post",
                dataType:"json",
                success:function (obj) {
                    for (let i in obj) {
                        $("[name='sheng']").append("<option value="+obj[i].id+">-"+obj[i].name+"-</option>")

                    }
                }
            })
            $("[name='sheng']").change(function () {
                var id=$(this).val();
                $("[name='xian']").empty();
                $("[name='xian']").append(" <option value=\"\">-请选择-</option>");
                $("[name='shi']").empty();
                $("[name='shi']").append(" <option value=\"\">-请选择-</option>");
                $.ajax({
                    url:"city.do",
                    data:{"pid":id},
                    type:"post",
                    dataType:"json",
                    success:function (obj) {
                        for (let i in obj) {
                            $("[name='shi']").append("<option value="+obj[i].id+">-"+obj[i].name+"-</option>")

                        }
                    }
                })
            })
            $("[name='shi']").change(function () {
                var id=$(this).val();
                $("[name='xian']").empty();
                $("[name='xian']").append(" <option value=\"\">-请选择-</option>");
                $.ajax({
                    url:"city.do",
                    data:{"pid":id},
                    type:"post",
                    dataType:"json",
                    success:function (obj) {
                        for (let i in obj) {
                            $("[name='xian']").append("<option value="+obj[i].id+">-"+obj[i].name+"-</option>")

                        }
                    }
                })
            })
        })
        function fh() {
            location.href="index.jsp"
        }
        function zc() {
            var formData = new FormData($("form")[0]);
            $.ajax({
                url:"add.do",
                data:formData,
                type:"post",
                dataType:"json",
                processData: false,
                contentType:false,
                success:function (obj) {
                    if(obj>0){
                        alert("添加成功");
                        location.href="list.do";
                    }
                }
            })
        }
    </script>
</head>
<body>
    <form>
        姓名：<input type="text" name="name"><br>
        密码：<input type="password" name="password"><br>
        性别：<input type="radio" name="sex" value="男">男
        <input type="radio" name="sex" value="女">女<br>
        爱好：
        <input type="checkbox" name="hobby" value="吃">吃
        <input type="checkbox" name="hobby" value="乐">乐
        <input type="checkbox" name="hobby" value="玩">玩
        <input type="checkbox" name="hobby" value="喝">喝<br>
        生日：<input type="date" name="bdate">
        <br><br>
        图片：<div class="photoUpLoad" >
        <input type="file"   class="photo" name="photo" accept="image/*"><span class="cross">+</span>
        <img src="" alt="" class="photoEcho">
    </div><br><br>

        省：
        <select name="sheng">
            <option value="">-请选择-</option>
        </select>
        市：
        <select name="shi">
            <option value="">-请选择-</option>
        </select>
        县：
        <select name="xian">
            <option value="">-请选择-</option>
        </select>
    </form>
    <br>
    <input type="button" value="注册" onclick="zc()">
    <input type="button" value="返回" onclick="fh()">
    <br>
</body>
</html>
